﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DataLibrary
{
    public class Ctbl_Member:IData<tbl_Member>
    {
        public Ctbl_Member(String myconnecString) : base(myconnecString) { 
        }

        public override List<tbl_Member> GetAll(tbl_Member item)
        {
            throw new NotImplementedException();
        }

        public override tbl_Member GetItemById(object id)
        {
            return GetAll().SingleOrDefault(p => p.IdMember == Convert.ToInt32(id));
        }

        public override tbl_Member GetItem(IDataReader dr)
        {
            tbl_Member obj = new tbl_Member();
            obj.Congty = Convert.ToString(dr[tbl_Member.c_congty]);
            obj.Diachi = Convert.ToString(dr[tbl_Member.c_diachi]);
            obj.Dienthoai= Convert.ToString(dr[tbl_Member.c_dienthoai]);
            obj.Email = Convert.ToString(dr[tbl_Member.c_email]);
            obj.Fax = Convert.ToString(dr[tbl_Member.c_fax]);
            obj.Gioitinh = Convert.ToBoolean(dr[tbl_Member.c_gioitinh]);
            obj.Hoten = Convert.ToString(dr[tbl_Member.c_hoten]);
            obj.IdMember = Convert.ToInt32(dr[tbl_Member.c_idMember]);
            obj.IdQuocgia = Convert.ToInt32(dr[tbl_Member.c_idQuocgia]);
            obj.IdTinhthanh= Convert.ToInt32(dr[tbl_Member.c_idTinhthanh]);
            obj.IsActive= Convert.ToInt32(dr[tbl_Member.c_isActive]);
            obj.Masothue = Convert.ToString(dr[tbl_Member.c_masothue]);
            obj.NgayDangky = Convert.ToDateTime(dr[tbl_Member.c_ngayDangky]);
            obj.Ngaysinh = Convert.ToDateTime(dr[tbl_Member.c_ngaysinh]);
            obj.Password= Convert.ToString(dr[tbl_Member.c_password]);
            obj.Quan = Convert.ToString(dr[tbl_Member.c_quan]);
            obj.Username = Convert.ToString(dr[tbl_Member.c_username]);
            obj.Website = Convert.ToString(dr[tbl_Member.c_website]);
            return obj;
        }

        public override List<tbl_Member> GetAll()
        {
            String strSQL = "select * from " + tbl_Member.b_tbl_Member + strAsc;
            return GetAll(strSQL, CommandType.Text);
        }


        protected override int InsertOnSubmit(tbl_Member item, int t)
        {
            int id = -1;
            String strProName = "ProMember";
            id = connec.ExecuteNonQuery(strProName,CommandType.StoredProcedure,new SqlParameter("@flag",t),
                new SqlParameter("@"+tbl_Member.c_congty,item.Congty),new SqlParameter("@"+tbl_Member.c_diachi,item.Diachi),
                new SqlParameter("@"+tbl_Member.c_dienthoai,item.Dienthoai),new SqlParameter("@"+tbl_Member.c_email,item.Email),
                new SqlParameter("@"+tbl_Member.c_fax,item.Fax),new SqlParameter("@"+tbl_Member.c_gioitinh,item.Gioitinh),
                new SqlParameter("@"+tbl_Member.c_hoten,item.Hoten),new SqlParameter("@"+tbl_Member.c_idMember,item.IdMember),
                new SqlParameter("@"+tbl_Member.c_idQuocgia,item.IdQuocgia),new SqlParameter("@"+tbl_Member.c_idTinhthanh,item.IdTinhthanh),
                new SqlParameter("@"+tbl_Member.c_isActive,item.IsActive),new SqlParameter("@"+tbl_Member.c_masothue,item.Masothue),
                new SqlParameter("@"+tbl_Member.c_ngayDangky,item.NgayDangky),new SqlParameter("@"+tbl_Member.c_ngaysinh,item.Ngaysinh),
                new SqlParameter("@"+tbl_Member.c_password,item.Password),new SqlParameter("@"+tbl_Member.c_quan,item.Quan),
                new SqlParameter("@"+tbl_Member.c_username,item.Username),new SqlParameter("@"+tbl_Member.c_website,item.Website));
            return id;
        }
    }
}
